package dietAndroidClient;

import java.util.Calendar;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.Log;
import android.view.View;

import com.mnk.TCPsoketTest.R;


	// �먮낯 : http://funpython.com/blog/59?category=2
	// �섏젙 : �쒖닔�� 
public class Oneday extends View {
 
    private int year;
    private int month;
    private int day;
    private int dayOfWeek;
     
    private String textDay;
    private String textActCnt;
 
    private Paint bgDayPaint;
    private Paint bgSelectedDayPaint;
    private Paint bgActcntPaint;
    private Paint bgTodayPaint;
    private Paint textDayPaint;
    private Paint textActcntPaint;
    
    private Paint check;//////////////
    
    private int textDayTopPadding;
    private int textDayLeftPadding;
    private int textActcntTopPadding;
    private int textActcntLeftPadding;
 
    private Paint mPaint;
 
    private boolean mSelected;
    public boolean isToday = false;
   
    private boolean mSelect;//////////////////////////
 
    
    Bitmap bitmapA = null;
    
    public Oneday(Context context , android.util.AttributeSet attrs) {
        super(context, attrs);
        init();
    }
 
    public Oneday(Context context) {
        super(context);
        init();
 
    }
 
    private void init()
    {
        bgDayPaint = new Paint();
        bgSelectedDayPaint = new Paint();
        bgActcntPaint = new Paint();
        textDayPaint = new Paint();
        textActcntPaint = new Paint();
        bgTodayPaint = new Paint();
        
        check = new Paint();//////////////
        
        bgDayPaint.setColor(Color.WHITE);
        bgActcntPaint.setColor(Color.YELLOW);
        textDayPaint.setColor(Color.WHITE);
        textDayPaint.setAntiAlias(true);
        textActcntPaint.setColor(Color.WHITE);
        textActcntPaint.setAntiAlias(true);
        bgTodayPaint.setColor(Color.GREEN);
        
        check = new Paint(Color.RED);//////////
        
        
        rect = new RectF();
 
        setTextDayTopPadding(0);
        setTextDayLeftPadding(0);
 
        setTextActcntTopPadding(0);
        setTextActcntLeftPadding(0);
 
        mPaint = new Paint();
 
        mSelected = false;
        
        bitmapA = BitmapFactory.decodeResource(getResources(), R.drawable.nullback);
    }
 
    RectF rect;
    @Override
    protected void onDraw(Canvas canvas) {
    	
    	Log.i("Oneday", "onDraw..............");
        if(mSelected){
            canvas.drawPaint(bgSelectedDayPaint);
        }else{
            if(isToday){
                canvas.drawPaint(bgTodayPaint);
            } else {
                canvas.drawPaint(bgDayPaint);
            }
        }
 
 
        int width = this.getWidth()/2;
        int height = this.getHeight()/2;
 
        int textDaysize = (int)textDayPaint.measureText(getTextDay()) / 2;
        int textActsize = (int)textActcntPaint.measureText(getTextActCnt()) / 2;
        canvas.drawText(getTextDay(), width - textDaysize + getTextDayLeftPadding(), height + getTextDayTopPadding(), textDayPaint);

        //	
//        if(getTextActCnt() != "")
//        {
//            rect.set(10, 45, 55, 65);
//            canvas.drawRoundRect(rect, 10, 30, bgActcntPaint);
//        }
 
    //    canvas.drawText(getTextActCnt(), width - textActsize + getTextActcntLeftPadding(), height + getTextActcntTopPadding(), textActcntPaint);
    //    canvas.drawBitmap(bitmapA, width - textActsize + getTextActcntLeftPadding() , height + getTextActcntTopPadding()/2, null);
          canvas.drawBitmap(bitmapA, 0, height, null);

        
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);
        canvas.drawLine(0, this.getHeight()-1, this.getWidth()-1, this.getHeight()-1, mPaint);
        canvas.drawLine(this.getWidth()-1, 0, this.getWidth()-1, this.getHeight()-1, mPaint);
    }
    
    // 활동 그림 찍는 함수
    public void bitmapA(String string){
    	Log.d("tag",string);
    	Canvas cv = new Canvas();
    	int str_int = Integer.parseInt(string);
    	switch(str_int){
    	case 0:
    		Log.d("str_int","0");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.nullback);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 1000:
    		Log.d("str_int","1000");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act01);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA, 0 , 0, null);
    		break;
    	case 100:
    		Log.d("str_int","100");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act02);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA, 0 , 0, null);
    		break;
    	case 10:
    		Log.d("str_int","10");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act03);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA, 0 , 0, null);
    		break;
    	case 1:
    		Log.d("str_int","1");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act04);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA, 0 , 0, null);
    		break;
    	case 1100:
    		Log.d("str_int","1100");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act05);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 1010:
    		Log.d("str_int","1010");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act06);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 1001:
    		Log.d("str_int","1001");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act07);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 110:
    		Log.d("str_int","110");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act08);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 101:
    		Log.d("str_int","101");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act09);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 11:
    		Log.d("str_int","11");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act10);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 1110:
    		Log.d("str_int","1110");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act11);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;

    	case 1101:
    		Log.d("str_int","1101");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act12);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 1011:
    		Log.d("str_int","1011");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act13);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 1111:
    		Log.d("str_int","1111");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act15);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	case 111:
    		Log.d("str_int","111");
    		bitmapA=BitmapFactory.decodeResource(getResources(), R.drawable.act14);
    		bitmapA=Bitmap.createScaledBitmap(bitmapA, 70, 20, false);
        	cv.drawBitmap(bitmapA,0, getHeight() + getTextActcntTopPadding(), null);
    		break;
    	}
    	
    	
    } // 그림 호출 종료
    
    public void testlog(Boolean[] itemschecked[]){
    	String str = null;
    	for(int i=0; i < 4 ; i++){
 		
    	}
    }

    public int getTextDayTopPadding() {
        return this.textDayTopPadding;
    }
    public int getTextDayLeftPadding() {
        return this.textDayLeftPadding;
    }
    public void setTextDayTopPadding(int top){
        this.textDayTopPadding = top;
    }
    public void setTextDayLeftPadding(int left){
        this.textDayLeftPadding = left;
    }
 
    public int getTextActcntTopPadding() {
        return this.textActcntTopPadding;
    }
    public int getTextActcntLeftPadding() {
        return this.textActcntLeftPadding;
    }
    public void setTextActcntTopPadding(int top){
        this.textActcntTopPadding = top;
    }
    public void setTextActcntLeftPadding(int left){
        this.textActcntLeftPadding = left;
    }
 
    public void setBgTodayPaint(int color){
        this.bgTodayPaint.setColor(color);
    }
    public void setBgDayPaint(int color){
        this.bgDayPaint.setColor(color);
    }
    public void setBgSelectedDayPaint(int color){
        this.bgSelectedDayPaint.setColor(color);
    }
    public void setBgActcntPaint(int color){
        this.bgActcntPaint.setColor(color);
    }
    public void setSelected(boolean selected){
        this.mSelected = selected;
    }
    public boolean getSelected() {
        return this.mSelected;
    }
 
    /**
     * �쇱옄���쒖떆��湲�由ы꽩
     * @return
     */
    public String getTextDay() {
        return this.textDay;
    }
    /**
     * �쇱옄���쒖떆��湲��낅젰
     * @param string
     */
    public void setTextDay(String string) {
        this.textDay = string;
    }
 
    /**
     *  遺�� �ㅻ챸���쒖떆��湲�由ы꽩
     * @return
     */
    public String getTextActCnt(){
        return this.textActCnt;
    }
    /**
     * 遺�� �ㅻ챸���쒖떆��湲��낅젰 
     * @param string
     */
    public void setTextActCnt(String string){
        this.textActCnt = string;
    }
    /**
     * �쇱옄 湲�뵪 �됱긽
     * @param color
     */
    public void setTextDayColor(int color){
        this.textDayPaint.setColor(color);
    }
    /**
     * �쇱옄 湲�뵪 �ш린
     * @param size
     */
    public void setTextDaySize(int size){
        this.textDayPaint.setTextSize(size);
    }
 
    /**
     *  遺�� �ㅻ챸 湲�옄 �됱긽
     * @param color
     */
    public void setTextActcntColor(int color){
        this.textActcntPaint.setColor(color);
    }
    /**
     * 遺�� �ㅻ챸 湲�옄 �ш린
     * @param size
     */
    public void setTextActcntSize(int size){
        this.textActcntPaint.setTextSize(size);
    }
     
    /**
     * �꾨룄
     * @param _year
     */
    public void setYear(int _year){
        year = _year;
    }
    /**
     * @return �꾨룄
     */
    public int getYear(){
        return year;
    }
 
    /**
     *  ��     *  
     * @param _month 0~11, Calendar.JANUARY ~ Calendar.DECEMBER
     */
    public void setMonth(int _month){
        month = Math.min(Calendar.DECEMBER, Math.max(Calendar.JANUARY, _month));
        month = _month;
    }
    /**
     * @return ��0~11, Calendar.JANUARY ~ Calendar.DECEMBER
     */
    public int getMonth(){
        return month;
    }
     
    /**
     * ��1~31
     */
    public void setDay(int _day){
        day = Math.min(31, Math.max(1, _day));
        day = _day;
    }
    /**
     * @return ��1~31
     */
    public int getDay(){
        return day;
    }
    /**
     * �붿씪 1~7<br/>
     * Calendar.SUNDAY ~ Calendar.SATURDAY
     */
    public void setDayOfWeek(int _dayOfWeek){
        dayOfWeek = Math.min(Calendar.SATURDAY, Math.max(Calendar.SUNDAY, _dayOfWeek));
        dayOfWeek = _dayOfWeek;
    }
     
    /**
     * @return �붿씪 1~7, Calendar.SUNDAY ~ Calendar.SATURDAY
     */
    public int getDayOfWeek(){
        return dayOfWeek;
    }
     
    /**
     * �대떦 �붿씪���쒓�濡�由ы꽩
     * @return "��, "��, "��, "��, "紐�, "湲�, "��
     */
    public String getDayOfWeekKorean(){
        final String[]korean = {"월", "화", "수", "목", "금", "토", "일"};
        return korean[dayOfWeek];
    }
     
    /**
     * �대떦 �붿씪���곸뼱濡�由ы꽩
     * @return "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur"
     */
    public String getDayOfWeekEnglish(){
        final String[]korean = {"E", "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur"};
        return korean[dayOfWeek];
    }
     
    /**
     * 湲곕낯 �뺣낫 蹂듭궗
     * @param srcDay
     */
    public void copyData(Oneday srcDay){
        setYear(srcDay.getYear());
        setMonth(srcDay.getMonth());
        setDay(srcDay.getDay());
        setDayOfWeek(srcDay.getDayOfWeek());
        setTextDay(srcDay.getTextDay());
        setTextActCnt(srcDay.getTextActCnt());
    }
     
}